#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct SNode *Stu;
struct SNode
{
    int id; char name[21]; int seat;
};

Stu CreateList(int n)
{
    Stu T = (Stu)malloc(n*sizeof(struct SNode));
    for(int i=0;i<n;i++)
    {
        T[i].id = T[i].seat = 0;
        memset(T[i].name, '\0', 21*sizeof(char));       
    }
    return T;
}

int cmp1(const void *a, const void *b)
{
    int BOOL = (((Stu)a)->seat > ((Stu)b)->seat);
    return (BOOL!=0 ? BOOL : (((Stu)a)->id > ((Stu)b)->id));
}

int cmp2(const void *a, const void *b)
{
    return (((Stu)a)->id > ((Stu)b)->id);
}

int main()
{
    FILE *IN, *OUT;
    if((IN = fopen("in.txt", "r")) == NULL)
    {
        printf("The file do not exist.\n");
        return -1;
    }
    OUT = fopen("out.txt", "w");
    int n, m = 0, q;
    scanf("%d", &n);
    Stu T1 = CreateList(n);
    int ID, SEAT; char NAME[21]; 
    for(int i=0;i<n;i++)
    {
        fscanf(IN, "%d %s %d\n", &ID, NAME, &SEAT);
        m = (m<SEAT ? SEAT : m);
        T1[i].id = ID; T1[i].seat = SEAT;
        strcpy(T1[i].name, NAME);
    }
    qsort(T1, n, sizeof(struct SNode), cmp1);

    int pos = n-1;
    q = (m<n ? m : n);
    int occupy[q+1]; memset(occupy, 0, sizeof(occupy));
    for(int k=0;k<n;k++) occupy[T1[k].seat] = 1;
    for(int j=1;j<=q;j++)
        if(!occupy[j] && T1[pos].seat > j)
            T1[pos--].seat = j;
    
    m = 0;
    for(int i=0;i<n;i++)
        m = (m<T1[i].seat ? T1[i].seat : m);
    for(int i=1;i<=pos;i++)
        if(T1[i].seat == T1[i-1].seat)
            T1[i].seat = ++m;

    qsort(T1, n, sizeof(struct SNode), cmp2);
    for(int i=0;i<n;i++)
        fprintf(OUT, "%d %s %d\n", T1[i].id, T1[i].name, T1[i].seat);
    return 0;
}